package com.example.ruihuada.ui.HomeModule.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.widget.PopupMenu
import androidx.recyclerview.widget.GridLayoutManager
import com.example.ruihuada.R
import com.example.ruihuada.ui.HomeModule.adapter.ShopDetailsAdapter
import com.noober.background.BackgroundLibrary
import kotlinx.android.synthetic.main.activity_shop_select.*

class ShopSelectActivity : AppCompatActivity() {
    val tilteList = mutableListOf(
        "云展播副赛",
        "山西太原田园风格大赛",
        "云展播副赛",
        "山西太原田园风格大赛",
        "云展播副赛",
        "山西太原田园风格大赛"
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        BackgroundLibrary.inject(this)
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_shop_select)
        recyclerview_detail.layoutManager = GridLayoutManager(this, 2)
        recyclerview_detail.adapter =
            ShopDetailsAdapter(tilteList)
        im_select.setOnClickListener {
            showPopupMenu()
        }
    }

    private fun showPopupMenu() {
        // View当前PopupMenu显示的相对View的位置
        val popupMenu = PopupMenu(this, btn)
        // menu布局
        popupMenu.getMenuInflater().inflate(R.menu.type, popupMenu.getMenu())
        // menu的item点击事件
        popupMenu.setOnMenuItemClickListener(object : PopupMenu.OnMenuItemClickListener {
            fun onMenuItemClick(): Boolean {
                return false
            }

            override fun onMenuItemClick(item: MenuItem?): Boolean {
                Toast.makeText(applicationContext, item?.getTitle(), Toast.LENGTH_SHORT).show()
                return false
            }
        })
        // PopupMenu关闭事件
        popupMenu.setOnDismissListener(object : PopupMenu.OnDismissListener {
            override fun onDismiss(menu: PopupMenu?) {
                Toast.makeText(applicationContext, "关闭PopupMenu", Toast.LENGTH_SHORT).show()
            }
        })
        popupMenu.show()
    }
}